package com.pengtu.gsj.service.impl.lwfw;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.lwfw.TrafficserviceDao;
import com.pengtu.gsj.entity.app.Attachment;
import com.pengtu.gsj.entity.lwfw.Trafficservice;
import com.pengtu.gsj.service.lwfw.TrafficserviceService;
import com.pengtu.gsj.service.system.SystemManageService;

@Service
@Transactional
public class TrafficserviceServiceImpl implements TrafficserviceService{

	@Autowired
	public TrafficserviceDao trafficserviceDao;
	@Autowired
	public SystemManageService systemManageService;
	
	@Override
	public Trafficservice getTrafficserviceById(String id) {
		return trafficserviceDao.get(id);
	}

	@Override
	public Page<Trafficservice> findTrafficservice(Page<Trafficservice> page, final QueryFilter queryFilter){
		return trafficserviceDao.findPage(page, queryFilter);
	}

	@Override
	public void saveTrafficservice(Trafficservice trafficservice) {
		trafficserviceDao.save(trafficservice);
	}

	@Override
	public void  delateTrafficservice(Trafficservice trafficservice){
		if(trafficservice.getAttachments() != null){
			for(Attachment attachment : trafficservice.getAttachments()){
				systemManageService.deleteAttachment(attachment);
			}
		}
		trafficserviceDao.delete(trafficservice);
	}

	@Override
	public Boolean checkServiceType(String serviceType, String id) {
		return trafficserviceDao.checkProperty("serviceType", serviceType, id);
	}
}
